package com.moco.launcher.activity;

import android.os.Bundle;
import android.view.MotionEvent;

import com.moco.launcher.LauncherApplication;
import com.moco.launcher.R;
import com.moco.launcher.fragment.BaseFragment;
import com.moco.launcher.fragment.PowerBackFragment;
import com.moco.launcher.fragment.PowerOffFragment;
import com.moco.launcher.listener.FragmentListener;
import com.oazon.common.Logger;

public class PowerOffActivity extends BaseFragmentActivity implements FragmentListener {
	private static final String TAG = "PowerOffActivity";
	
	private LauncherApplication mApp = null;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		this.setContentView(R.layout.pop_layout);

		mApp = ((LauncherApplication)getApplication());
		mApp.registerActivty(this);
		
		BaseFragment fragment = new PowerOffFragment();
		fragment.registerCallback(this);
		getSupportFragmentManager().beginTransaction().replace(R.id.fragment, fragment).commit();
	}

	public void displayListFlagment() {
		PowerBackFragment fr = new PowerBackFragment();
		String tag = PowerBackFragment.class.getSimpleName();
		fr = (PowerBackFragment) getSupportFragmentManager().findFragmentByTag(tag);
		if (fr == null) {
			fr = new PowerBackFragment();
			fr.registerCallback(this);
		}
		getSupportFragmentManager().beginTransaction().replace(R.id.fragment, fr, tag).commit();
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		Logger.d(TAG, "the launcher receive dispatchTouchEvent event");
		
		mApp.resetStartTime();
		return super.dispatchTouchEvent(event);
	}

	@Override
	public void finishActivity() {
		this.finish();
	}
}
